def function-Name(self,argument,...,**kwargument): Statements ---------- return value
class Person: def setData(self,nm,**info): self.name=nm self.info=info def showData(self): print("Name is",self.name) for key,val in self.info.items(): print(key,"is",val) a=Person() a.setData("Amit Jain",age=23,city="Amravati",gender="M") a.showData() b=Person() b.setData("Raja Rathi",contactno=98473763,bdate="22-aug-1955") b.showData()
Name is Amit Jain Age is 23 City is Amravati Gender is M Name is Raja Rathi Contactno is 98473763 Bdate is 22-aug-1955
class Sales: def setData(self,cmp,yr,**sinfo): self.company=cmp self.year=yr self.salesinfo=sinfo def showData(self): print("Company is",self.company) print("Year is",self.year) for key,val in self.salesinfo.items(): print(key,"sales",val) a=Sales() a.setData("Maruti",2020,alto=55320,swift=44000,wagnor=11250) a.showData() b=Sales() b.setData("Tata",2020,nano=250,tigor=35400) b.showData()
Company is Maruti Year is 2020 alto sales 55320 swift sales 44000 wagnor sales 11250 Company is Tata Year is 2020 nano sales 250 tigor sales 35400